<?php
class Api_Default extends PhalApi_Api {
	public function getRules() {
		return array(
			'index' => array(
				'info' 	=> array('name' => 'info', 'default' => null),
			),
			'detail'=> array(),
		);
	}
	
	public function index() {
		if (is_null($this->info)) {
			return ['time'=> $_SERVER['REQUEST_TIME'], 'result'=> 0];
		}
		$info = json_decode($this->info, 1);
		if ($info) {
			// 数据正确，存入数据库
			DI()->notorm->mt4->insert($info);
			// 返回结果
			return ['time'=> $_SERVER['REQUEST_TIME'], 'result'=> 1];
		}
		return ['time'=> $_SERVER['REQUEST_TIME'], 'result'=> 0, 'source'=> $this->info];
	}

	public function detail() {
		$result = DI()->notorm->mt4->order('id desc')->limit(50);
		return $result;
	}
}